// pages/yongjin/yongjin.js
import { getUserInfo,getMoneyRecord,postExtractCash} from '../../api/user.js'; 
import {getIndexData} from '../../api/api'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        parameter: {
            'navbar': '1',
            'return': '1',
            'title': '佣金明细',
            'color': false,
        },
        navH:'',

        userinfo:'',
        page:1,
        loading:true,
        list:[],
        limit:20,
    
        tx_type:[
           {name:'支付宝','val':'alipay'},
           {name:'微信','val':'weixin'},
           {name:'银行卡','val':'bank'},
        ],
        tx_index:0,
        name:'',
        alipay_code:'',
        weixin:'',
        bankname:'',
        cardnum:'',
        money:'',
        isshow:false,
        is_withdrawal:false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            navH: getApp().globalData.navHeight
        });
        getIndexData().then(res=>{
               this.setData({
                    is_withdrawal:res.data.is_withdrawal
               })
        }).catch(e=>{})
    }, 

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getuserinfo() 
        let that = this;
        that.setData({
            loading:false
        },function(){
            that.getlist()
        }) 
    },

    //会员信息
  getuserinfo(){
    getUserInfo().then(res=>{
            this.setData({
                userinfo:res.data
            })
    }).catch(e=>{})
},
getlist(){
    let data ={
        page:this.data.page,
        limit:this.data.limit
    }
    getMoneyRecord(data).then(res=>{
        if(this.data.page==1){
            this.setData({
                  list:res.data,
                  page:this.data.page+1,
                  loading:res.data.length>=this.data.limit
            })
        }else{
            this.setData({
                list:this.data.list.concat(res.data),
                page:this.data.page+1,
                loading:res.data.length>=this.data.limit
            })
        }
    }).catch(e=>{})
},

txjl(){
    wx.navigateTo({
       url:'./tx_history'
    })
},

tx(){
    this.setData({
        isshow : !this.data.isshow
      })
},
//选择提现类型
xztype(e){ 
    this.setData({
        tx_index:e.detail.value,
        name:'',
        alipay_code:'',
        weixin:'',
        bankname:'',
        cardnum:'',
    })
},

txsq(){
   let data ={
      extract_type:this.data.tx_type[this.data.tx_index].val,
      name:this.data.name,
      alipay_code:this.data.alipay_code,
      weixin:this.data.weixin,
      bankname:this.data.bankname,
      cardnum:this.data.cardnum,
      money:this.data.money,
   }
   wx.showLoading()
   postExtractCash(data).then(res=>{
      wx.hideLoading()
      getApp().Tips({title:res.msg})
      this.getuserinfo()
      let that =this;
      that.setData({
          name:'',
          alipay_code:'',
          weixin:'',
          bankname:'',
          cardnum:'',
          money:'',
      })
      that.setData({
          page:1,
          loading:true
      },function(){
          that.getlist()
      })
   }).catch(e=>{
      wx.hideLoading()
      getApp().Tips({title:e})
   })

},

//input
ininput(e){
    let type = e.currentTarget.dataset.type;
    this.setData({
          [type]:e.detail.value
    })
},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if(this.data.loading){
            let that = this;
            that.setData({
                loading:false
            },function(){
             that.getlist()
            })
       }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})